#pragma once
// MESSAGE PWM_MOTOR PACKING

#define MAVLINK_MSG_ID_PWM_MOTOR 161

MAVPACKED(
typedef struct __mavlink_pwm_motor_t {
 uint16_t motor1; /*<  PWM_MOTOR1*/
 uint16_t motor2; /*<  PWM_MOTOR2*/
 uint16_t motor3; /*<  PWM_MOTOR3*/
 uint16_t motor4; /*<  PWM_MOTOR4*/
 uint16_t motor5; /*<  PWM_MOTOR5*/
}) mavlink_pwm_motor_t;

#define MAVLINK_MSG_ID_PWM_MOTOR_LEN 10
#define MAVLINK_MSG_ID_PWM_MOTOR_MIN_LEN 10
#define MAVLINK_MSG_ID_161_LEN 10
#define MAVLINK_MSG_ID_161_MIN_LEN 10

#define MAVLINK_MSG_ID_PWM_MOTOR_CRC 35
#define MAVLINK_MSG_ID_161_CRC 35



#if MAVLINK_COMMAND_24BIT
#define MAVLINK_MESSAGE_INFO_PWM_MOTOR { \
    161, \
    "PWM_MOTOR", \
    5, \
    {  { "motor1", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_pwm_motor_t, motor1) }, \
         { "motor2", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_pwm_motor_t, motor2) }, \
         { "motor3", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_pwm_motor_t, motor3) }, \
         { "motor4", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_pwm_motor_t, motor4) }, \
         { "motor5", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_pwm_motor_t, motor5) }, \
         } \
}
#else
#define MAVLINK_MESSAGE_INFO_PWM_MOTOR { \
    "PWM_MOTOR", \
    5, \
    {  { "motor1", NULL, MAVLINK_TYPE_UINT16_T, 0, 0, offsetof(mavlink_pwm_motor_t, motor1) }, \
         { "motor2", NULL, MAVLINK_TYPE_UINT16_T, 0, 2, offsetof(mavlink_pwm_motor_t, motor2) }, \
         { "motor3", NULL, MAVLINK_TYPE_UINT16_T, 0, 4, offsetof(mavlink_pwm_motor_t, motor3) }, \
         { "motor4", NULL, MAVLINK_TYPE_UINT16_T, 0, 6, offsetof(mavlink_pwm_motor_t, motor4) }, \
         { "motor5", NULL, MAVLINK_TYPE_UINT16_T, 0, 8, offsetof(mavlink_pwm_motor_t, motor5) }, \
         } \
}
#endif

/**
 * @brief Pack a pwm_motor message
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
 *
 * @param motor1  PWM_MOTOR1
 * @param motor2  PWM_MOTOR2
 * @param motor3  PWM_MOTOR3
 * @param motor4  PWM_MOTOR4
 * @param motor5  PWM_MOTOR5
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_pwm_motor_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg,
                               uint16_t motor1, uint16_t motor2, uint16_t motor3, uint16_t motor4, uint16_t motor5)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_PWM_MOTOR_LEN];
    _mav_put_uint16_t(buf, 0, motor1);
    _mav_put_uint16_t(buf, 2, motor2);
    _mav_put_uint16_t(buf, 4, motor3);
    _mav_put_uint16_t(buf, 6, motor4);
    _mav_put_uint16_t(buf, 8, motor5);

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_PWM_MOTOR_LEN);
#else
    mavlink_pwm_motor_t packet;
    packet.motor1 = motor1;
    packet.motor2 = motor2;
    packet.motor3 = motor3;
    packet.motor4 = motor4;
    packet.motor5 = motor5;

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_PWM_MOTOR_LEN);
#endif

    msg->msgid = MAVLINK_MSG_ID_PWM_MOTOR;
    return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_PWM_MOTOR_MIN_LEN, MAVLINK_MSG_ID_PWM_MOTOR_LEN, MAVLINK_MSG_ID_PWM_MOTOR_CRC);
}

/**
 * @brief Pack a pwm_motor message on a channel
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param chan The MAVLink channel this message will be sent over
 * @param msg The MAVLink message to compress the data into
 * @param motor1  PWM_MOTOR1
 * @param motor2  PWM_MOTOR2
 * @param motor3  PWM_MOTOR3
 * @param motor4  PWM_MOTOR4
 * @param motor5  PWM_MOTOR5
 * @return length of the message in bytes (excluding serial stream start sign)
 */
static inline uint16_t mavlink_msg_pwm_motor_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan,
                               mavlink_message_t* msg,
                                   uint16_t motor1,uint16_t motor2,uint16_t motor3,uint16_t motor4,uint16_t motor5)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_PWM_MOTOR_LEN];
    _mav_put_uint16_t(buf, 0, motor1);
    _mav_put_uint16_t(buf, 2, motor2);
    _mav_put_uint16_t(buf, 4, motor3);
    _mav_put_uint16_t(buf, 6, motor4);
    _mav_put_uint16_t(buf, 8, motor5);

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_PWM_MOTOR_LEN);
#else
    mavlink_pwm_motor_t packet;
    packet.motor1 = motor1;
    packet.motor2 = motor2;
    packet.motor3 = motor3;
    packet.motor4 = motor4;
    packet.motor5 = motor5;

        memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_PWM_MOTOR_LEN);
#endif

    msg->msgid = MAVLINK_MSG_ID_PWM_MOTOR;
    return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_PWM_MOTOR_MIN_LEN, MAVLINK_MSG_ID_PWM_MOTOR_LEN, MAVLINK_MSG_ID_PWM_MOTOR_CRC);
}

/**
 * @brief Encode a pwm_motor struct
 *
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param msg The MAVLink message to compress the data into
 * @param pwm_motor C-struct to read the message contents from
 */
static inline uint16_t mavlink_msg_pwm_motor_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_pwm_motor_t* pwm_motor)
{
    return mavlink_msg_pwm_motor_pack(system_id, component_id, msg, pwm_motor->motor1, pwm_motor->motor2, pwm_motor->motor3, pwm_motor->motor4, pwm_motor->motor5);
}

/**
 * @brief Encode a pwm_motor struct on a channel
 *
 * @param system_id ID of this system
 * @param component_id ID of this component (e.g. 200 for IMU)
 * @param chan The MAVLink channel this message will be sent over
 * @param msg The MAVLink message to compress the data into
 * @param pwm_motor C-struct to read the message contents from
 */
static inline uint16_t mavlink_msg_pwm_motor_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_pwm_motor_t* pwm_motor)
{
    return mavlink_msg_pwm_motor_pack_chan(system_id, component_id, chan, msg, pwm_motor->motor1, pwm_motor->motor2, pwm_motor->motor3, pwm_motor->motor4, pwm_motor->motor5);
}

/**
 * @brief Send a pwm_motor message
 * @param chan MAVLink channel to send the message
 *
 * @param motor1  PWM_MOTOR1
 * @param motor2  PWM_MOTOR2
 * @param motor3  PWM_MOTOR3
 * @param motor4  PWM_MOTOR4
 * @param motor5  PWM_MOTOR5
 */
#ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS

static inline void mavlink_msg_pwm_motor_send(mavlink_channel_t chan, uint16_t motor1, uint16_t motor2, uint16_t motor3, uint16_t motor4, uint16_t motor5)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char buf[MAVLINK_MSG_ID_PWM_MOTOR_LEN];
    _mav_put_uint16_t(buf, 0, motor1);
    _mav_put_uint16_t(buf, 2, motor2);
    _mav_put_uint16_t(buf, 4, motor3);
    _mav_put_uint16_t(buf, 6, motor4);
    _mav_put_uint16_t(buf, 8, motor5);

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PWM_MOTOR, buf, MAVLINK_MSG_ID_PWM_MOTOR_MIN_LEN, MAVLINK_MSG_ID_PWM_MOTOR_LEN, MAVLINK_MSG_ID_PWM_MOTOR_CRC);
#else
    mavlink_pwm_motor_t packet;
    packet.motor1 = motor1;
    packet.motor2 = motor2;
    packet.motor3 = motor3;
    packet.motor4 = motor4;
    packet.motor5 = motor5;

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PWM_MOTOR, (const char *)&packet, MAVLINK_MSG_ID_PWM_MOTOR_MIN_LEN, MAVLINK_MSG_ID_PWM_MOTOR_LEN, MAVLINK_MSG_ID_PWM_MOTOR_CRC);
#endif
}

/**
 * @brief Send a pwm_motor message
 * @param chan MAVLink channel to send the message
 * @param struct The MAVLink struct to serialize
 */
static inline void mavlink_msg_pwm_motor_send_struct(mavlink_channel_t chan, const mavlink_pwm_motor_t* pwm_motor)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    mavlink_msg_pwm_motor_send(chan, pwm_motor->motor1, pwm_motor->motor2, pwm_motor->motor3, pwm_motor->motor4, pwm_motor->motor5);
#else
    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PWM_MOTOR, (const char *)pwm_motor, MAVLINK_MSG_ID_PWM_MOTOR_MIN_LEN, MAVLINK_MSG_ID_PWM_MOTOR_LEN, MAVLINK_MSG_ID_PWM_MOTOR_CRC);
#endif
}

#if MAVLINK_MSG_ID_PWM_MOTOR_LEN <= MAVLINK_MAX_PAYLOAD_LEN
/*
  This varient of _send() can be used to save stack space by re-using
  memory from the receive buffer.  The caller provides a
  mavlink_message_t which is the size of a full mavlink message. This
  is usually the receive buffer for the channel, and allows a reply to an
  incoming message with minimum stack space usage.
 */
static inline void mavlink_msg_pwm_motor_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan,  uint16_t motor1, uint16_t motor2, uint16_t motor3, uint16_t motor4, uint16_t motor5)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    char *buf = (char *)msgbuf;
    _mav_put_uint16_t(buf, 0, motor1);
    _mav_put_uint16_t(buf, 2, motor2);
    _mav_put_uint16_t(buf, 4, motor3);
    _mav_put_uint16_t(buf, 6, motor4);
    _mav_put_uint16_t(buf, 8, motor5);

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PWM_MOTOR, buf, MAVLINK_MSG_ID_PWM_MOTOR_MIN_LEN, MAVLINK_MSG_ID_PWM_MOTOR_LEN, MAVLINK_MSG_ID_PWM_MOTOR_CRC);
#else
    mavlink_pwm_motor_t *packet = (mavlink_pwm_motor_t *)msgbuf;
    packet->motor1 = motor1;
    packet->motor2 = motor2;
    packet->motor3 = motor3;
    packet->motor4 = motor4;
    packet->motor5 = motor5;

    _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_PWM_MOTOR, (const char *)packet, MAVLINK_MSG_ID_PWM_MOTOR_MIN_LEN, MAVLINK_MSG_ID_PWM_MOTOR_LEN, MAVLINK_MSG_ID_PWM_MOTOR_CRC);
#endif
}
#endif

#endif

// MESSAGE PWM_MOTOR UNPACKING


/**
 * @brief Get field motor1 from pwm_motor message
 *
 * @return  PWM_MOTOR1
 */
static inline uint16_t mavlink_msg_pwm_motor_get_motor1(const mavlink_message_t* msg)
{
    return _MAV_RETURN_uint16_t(msg,  0);
}

/**
 * @brief Get field motor2 from pwm_motor message
 *
 * @return  PWM_MOTOR2
 */
static inline uint16_t mavlink_msg_pwm_motor_get_motor2(const mavlink_message_t* msg)
{
    return _MAV_RETURN_uint16_t(msg,  2);
}

/**
 * @brief Get field motor3 from pwm_motor message
 *
 * @return  PWM_MOTOR3
 */
static inline uint16_t mavlink_msg_pwm_motor_get_motor3(const mavlink_message_t* msg)
{
    return _MAV_RETURN_uint16_t(msg,  4);
}

/**
 * @brief Get field motor4 from pwm_motor message
 *
 * @return  PWM_MOTOR4
 */
static inline uint16_t mavlink_msg_pwm_motor_get_motor4(const mavlink_message_t* msg)
{
    return _MAV_RETURN_uint16_t(msg,  6);
}

/**
 * @brief Get field motor5 from pwm_motor message
 *
 * @return  PWM_MOTOR5
 */
static inline uint16_t mavlink_msg_pwm_motor_get_motor5(const mavlink_message_t* msg)
{
    return _MAV_RETURN_uint16_t(msg,  8);
}

/**
 * @brief Decode a pwm_motor message into a struct
 *
 * @param msg The message to decode
 * @param pwm_motor C-struct to decode the message contents into
 */
static inline void mavlink_msg_pwm_motor_decode(const mavlink_message_t* msg, mavlink_pwm_motor_t* pwm_motor)
{
#if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS
    pwm_motor->motor1 = mavlink_msg_pwm_motor_get_motor1(msg);
    pwm_motor->motor2 = mavlink_msg_pwm_motor_get_motor2(msg);
    pwm_motor->motor3 = mavlink_msg_pwm_motor_get_motor3(msg);
    pwm_motor->motor4 = mavlink_msg_pwm_motor_get_motor4(msg);
    pwm_motor->motor5 = mavlink_msg_pwm_motor_get_motor5(msg);
#else
        uint8_t len = msg->len < MAVLINK_MSG_ID_PWM_MOTOR_LEN? msg->len : MAVLINK_MSG_ID_PWM_MOTOR_LEN;
        memset(pwm_motor, 0, MAVLINK_MSG_ID_PWM_MOTOR_LEN);
    memcpy(pwm_motor, _MAV_PAYLOAD(msg), len);
#endif
}
